var vm_table = new Vue({
    el: "#vm_table",
    data: {
        // 列表数据
        pageInfo: new Object(),
        column: [["id", "id", "onlyRead"],
            ["学生姓名", "stuname", "onlyRead"],
            ["性别", "stusex", "onlyRead"],
            ["班级id", "classid", "onlyRead"],
            ["选择就业公司", "jobcomid", "select"]],
        allJobCompany: [],
        // 所有班级
        allClass: [],
        // 搜索请求的班级
        queryClassId: 0,
        // 多选框部分
        checkBox: [],
        checked: false,
        flag: 0
    },
    methods: {
        getAllClass: function () {
            this.$http.get("joinjob/classList").then(function (value) {
                this.allClass = value.body;
            }, function (reason) {
                alert(reason.body["msg"]);
            });
        },
        getAllJobCom: function () {
            this.$http.get("joinjob/jobcompany").then(function (value) {
                this.allJobCompany = value.body;
            }, function (reason) {
                alert(reason.body["msg"]);
            })
        },
        query: function () {
            this.$http.get("joinjob/" + this.queryClassId + "/1").then(function (value) {
                this.pageInfo = value.body;
            }, function (reason) {
                alert(reason.body["msdg"]);
            })
        },
        addClass: function () {
            // 对勾选的学生分配工作
            if (this.checkBox.length == 0)
                alert("请选择同学。");

            this.flag = this.checkBox.length;
            this.checkBox.forEach(function (value, index) {
                vm_table.$http.post("joinjob", vm_table.pageInfo.list[value]).then(function (value) {
                    vm_table.flag--;
                }, function (reason) {
                    alert(reason.body["msg"])
                });
            });
        }
    },
    watch: {
        'checked': {
            handler: function (val, oldVal) {
                if (val) {
                    vm_table.checkBox = [];
                    for (var i = 0; i < vm_table.pageInfo.list.length; i++) {
                        vm_table.checkBox.push(i)
                    }
                } else {
                    vm_table.checkBox = [];
                }
            },
            deep: true
        },
        'flag': {
            handler: function (val, oldVal) {
                if (oldVal > 0 && val == 0) {
                    alert("success.全部插入。");
                    vm_table.query();
                }
            },
            deep: true
        }
    }
});

// init
vm_table.getAllClass();
vm_table.getAllJobCom();